#include "stm32f10x.h"


void ADC_INIT(void){
	GPIO_InitTypeDef GPIO_InitStruct;
	ADC_InitTypeDef ADC_InitStruct;
	
	//使用ADC1 Channel_3
	ADC_TypeDef* ADC_x=ADC1;
	uint8_t ADC_CHANNEL=3;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_GPIOA,ENABLE);
	
	GPIO_InitStruct.GPIO_Pin=GPIO_Pin_3;
	GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AIN;
	GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStruct);
	
	ADC_InitStruct.ADC_Mode = ADC_Mode_Independent;
	ADC_InitStruct.ADC_ScanConvMode = DISABLE;
	ADC_InitStruct.ADC_ContinuousConvMode = ENABLE;
	ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_InitStruct.ADC_NbrOfChannel = 1;
	ADC_Init(ADC_x,&ADC_InitStruct);

	RCC_ADCCLKConfig(RCC_PCLK2_Div8);
	ADC_RegularChannelConfig(ADC_x, ADC_CHANNEL,1,ADC_SampleTime_239Cycles5);
	
	ADC_ITConfig(ADC_x,ADC_IT_EOC,ENABLE);
	ADC_Cmd(ADC_x,ENABLE);
	
	ADC_StartCalibration(ADC_x);// ADC开始校准
	while(ADC_GetCalibrationStatus(ADC_x));//等待校准完成
	ADC_SoftwareStartConvCmd(ADC_x,ENABLE);
	
}
